package com.zecan.blog.utils;

import org.elasticsearch.common.Strings;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;

/**
 * @ClassName StringUtils
 * @Description
 * @date 2022/11/2 16:42
 * @Version 1.0
 */

public class StringUtils {

    // 检查是否是邮箱类型
    public static boolean isEmail(String email) {
        if ((email != null) && (!email.isEmpty())) {
            return Pattern.matches("^(\\w+([-.][A-Za-z0-9]+)*){3,18}@\\w+([-.][A-Za-z0-9]+)*\\.\\w+([-.][A-Za-z0-9]+)*$", email);
        }
        return false;
    }

    public static String dateFormat(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String datef = sdf.format(date);
        return datef;
    }

    public static  String shortDate(String date) {
        return Strings.substring(date,5,19);
    }

    public static String random() {
        return String.valueOf((int)((Math.random()*9+1)*10000));
    }

    public static String concatRedisGoodsKey() {
        return "userGood:";
    }

    public static String concatRedisDelGoodsKey() {
        return "userDelGood:";
    }

    public static String concatQuartzStr() {
        return BlogConstant.QUARTZ_ADD_GOOD_JOB_NAME  ;
    }

    public static String concatRedisViewKey(Integer userId) {
        return BlogConstant.FOLLOW_USER + userId;
    }

    public static String concatRedisViewHashKey(Integer followUserId, Integer followerUserId) {
        return followUserId + "_" + followerUserId;
    }

    public static String concatChattingUsers(Integer loginUserId,Integer friendUserId) {
        int max = Math.max(loginUserId,friendUserId);
        int min = Math.min(loginUserId,friendUserId);
        return min + "_" + max;
    }
}
